package com.custom.adz.custom;

import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by adz on 2017/5/8.
 * 自定义吐司样式
 */

public class ToastUtil {
    private Toast mToast;
    private TextView loginTV;
    private TextView registerTV;
    private LinearLayout llRegister;
    private LinearLayout llLogin;

    public ToastUtil(Context context, int layoutId, String msg,int tag){
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(layoutId, null);
        switch (tag) {
            //登录
            case 1:
                llLogin= (LinearLayout) view.findViewById(R.id.ll_login);
                llRegister= (LinearLayout) view.findViewById(R.id.ll_register);
                llLogin.setVisibility(View.VISIBLE);
                llRegister.setVisibility(View.GONE);
                loginTV= (TextView) view.findViewById(R.id.tv_toast_msg);
                loginTV.setText(msg);
                break;
            //注册
            case 2:
                llLogin= (LinearLayout) view.findViewById(R.id.ll_login);
                llRegister= (LinearLayout) view.findViewById(R.id.ll_register);
                llRegister.setVisibility(View.VISIBLE);
                llLogin.setVisibility(View.GONE);
                registerTV= (TextView) view.findViewById(R.id.tv_register_toast);
                registerTV.setText(msg);
                break;
        }
        if (mToast == null) {
            mToast = new Toast(context);
        }
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setDuration(Toast.LENGTH_LONG);
        mToast.setView(view);
    }

    public void show() {
        mToast.show();
    }
}
